Home How to convert custom blogs dynamic URL to static URL?
Reply: 1

How to convert custom blogs dynamic URL to static URL?

Nitin Jain
1#
Nitin Jain Published in 2017-11-09 19:50:50Z

I'm using https://example.com/post?id=post_name in my custom blog built with PHP and I want to use https://example.com/post_name instead.

But I also use http://example.com/deal?id=deal_name for displaying online shopping deals and I also want to change that to http://example.com/deal_name.

How do I do it? My current .htaccess file is this :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(([A-Za-z0-9\-]+/)*[A-Za-z0-9\-]+)?$ $1.php
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
Options -Indexes
Alberto Martinez
2#
Alberto Martinez Reply to 2017-11-09 21:34:08Z

You can't do exactly what you want because you want to rewrite URLs to two different pages so you need to differentiate one type of URL from the other.

For example you could use https://example.com/posts/post_name for the post URLs and http://example.com/deals/deal_name for deals, you can do this adding the following rules before the current rules of your .htaccess file (just after RewriteEngine On):

RewriteRule ^posts/(.+)$ /post?id=$1 [NC]
RewriteRule ^deals/(.+)$ /deal?id=$1 [NC]

Another option is if post_name and deal_name have always a token that differentiate both types, for example if post_name starts always with p- and deal_name starst always with d- you could use:

RewriteRule ^p-(.+)$ /post?id=p-$1 [NC]
RewriteRule ^d-(.+)$ /deal?id=d-$1 [NC]
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302358 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO