How can I change my URL from showing: www.example.com/p/tools to just www.example.com/tools?
I've tried to play around with the .htaccess a little bit, but unfortunately couldn't make it work.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
</IfModule>
Based on your shown samples, could you please try following.
Please make sure to clear your browser cache before testing your URLs
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
RewriteRule ^p/(.*)/?$ $1 [NC,R=301,L]
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
</IfModule>
Related
RewriteEngine On
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.elancemart\.com [NC]
RewriteRule (.*) https://elancemart.com/$1 [L,R=301]
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^services/([a-zA-Z0-9-]+) service_details.php?slug=$1 [NC,L]
RewriteRule ^category/([a-zA-Z-]+) category.php?catSlug=$1 [NC,L]
RewriteRule ^blog/([0-9]+)/([a-zA-Z0-9-]+) blog/article.php?id=$1&&slug=$2 [NC,L]
RewriteRule ^verify/([a-zA-Z0-9-]+) verify.php?verify=$1 [NC,L]
RewriteRule ^services services.php
RewriteRule ^services/page/([\d])$ /services.php?page=$1 [NC,L,QSA]
RewriteRule ^funds add-funds.php [NC,L]
RewriteRule ^sitemap\.xml/?$ sitemap.php
RewriteRule ^article-sitemap\.xml/?$ article-sitemap.php
ErrorDocument 404 /index.php
I am getting 404 error when hitting services/page/([\d+])$ /services.php?page=$1
The file exists, though When I change the rewrite rule to service/page/([\d+])$ it is working fine, I need services in the URL, not service.
With your shown samples, please try following htaccess rules in your htaccess file. I have put 3 of services rules one after another to make it easy looking.
Also make sure your htaccess file is present along side with servcies.php file.
Please make sure to clear your browser cache before testing your URLs.
RewriteEngine On
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.elancemart\.com [NC]
RewriteRule ^(.*)/?$ https://elancemart.com/$1 [L,R=301]
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)/?$ $1.php [L]
RewriteRule ^services/(\w+)/?$ service_details.php?slug=$1 [NC,L]
RewriteRule ^services/?$ services.php [NC,L]
RewriteRule ^services/page/(\d+)/?$ services.php?page=$1 [NC,L,QSA]
RewriteRule ^category/([a-zA-Z-]+)/?$ category.php?catSlug=$1 [NC,L]
RewriteRule ^blog/([0-9]+)/(\w+)/?$ blog/article.php?id=$1&&slug=$2 [NC,L]
RewriteRule ^verify/(\w+)/?$ verify.php?verify=$1 [NC,L]
RewriteRule ^funds/?$ add-funds.php [NC,L]
RewriteRule ^sitemap.xml/?$ sitemap.php [NC,L]
RewriteRule ^article-sitemap.xml/?$ article-sitemap.php [NC,L]
ErrorDocument 404 /index.php
I am getting 500 Internal Server Error when i wrote the twice file name from the url.
I am using the following RewriteRule for the user Profile url:
RewriteRule ^profile/([^/]+)/?$ profile.php?username=$1 [L,QSA,NC]
RewriteRule ^profile/(followers|friends|saved|stories)/([^/]+)/?$ $1.php?username=$2 [L,QSA,NC]
The Rules working working fine with this link:
https://www.thewebsiteurl.com/profile/username
But if i wrote the file name twice like this
https://www.thewebsiteurl.com/profile/profile/username
then i am getting the 500 Internal Server Error.
Is there any answer here to fix this problem ?
Here is my Full of my HTACCESS codes:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
ErrorDocument 404 https://www.websiteurl.com/sources/not-found.php
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,NE,L]
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index\.php$ /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^profile/([^/]+)/?$ profile.php?username=$1 [L,QSA,NC]
RewriteRule ^profile/(followers|friends|saved|stories)/([^/]+)/?$ $1.php?username=$2 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin '*'
</IfModule>
Rules appear to fine though I have seen in some web servers that %{REQUEST_FILENAME}.php doesn't work properly due to file name resolution issues.
Can you try changing that rule to this:
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
I am trying to beautify my URLs and want to get rid of the .php file extension. I've found a couple of other questions here such as this one (Removing the PHP file type extension) But none of the suggestions work for me. They send me to my 404.php or do not change the URL at all.
I figure the entire RewriteEngine code in my htaccess as a whole is conflicting in itself.
Here's what I got so far,
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /404.php [R]
</IfModule>
I would like my domains to look like
https://www.example.com/about
Don't mix Redirect, RedirectMatch and RewriteRule directives in same .htaccess as they come from different Apache modules and their load sequence is unpredictable.
Have it this way:
ErrorDocument 404 /404.php
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
Make sure to clear your browser cache before testing this change.
Put in .htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^ - [L]
#1)externally redirect "/file.php" to "/file"
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
#2)Internally map "/file" back to "/file.php"
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [NC,L]
ErrorDocument 404 ./404
RewriteCond %{REQUEST_URI} ^404/$
RewriteRule ^(.*)$ ./404 [L]
Redirect 301 /index /
remove .php from the link :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
I provided this .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.lebmotors.com/new/
RewriteRule (.*) http://www.lebmotors.com/new/$1 [R=301,L]
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ moreprod.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ moreprod.php?id=$1
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ moreprod.php?id=$1&topid=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ moreprod.php?id=$1&topid=$2
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ moreprod.php?id=$1&topid=$2&catid=$3
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ moreprod.php?id=$1&topid=$2&catid=$3
Still it does not work
I get: http://www.lebmotors.com/new/moreprod.php?id=107&topid=4&catid=8
What AM I doing wrong
Many Thanks
First of all, you don't need to repeat RewriteEngine On directive.
Then, when you add your rules, you still can access your pages via moreprod.php (but you can also access it from new clean url).
Here's how your htaccess should look like, assuming moreprod.php is also in new folder
Options -MultiViews
RewriteEngine On
RewriteBase /new/
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/? [R=301,L]
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)&topid=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/%2/? [R=301,L]
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)&topid=([^&\s]+)&catid=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/%2/%3/? [R=301,L]
RewriteCond %{THE_REQUEST} /morenews\.php\?id=([^&\s]+)\s [NC]
RewriteRule . morenews/%1/? [R=301,L]
RewriteRule ^morenews/([^/]+)/$ morenews.php?id=$1 [L]
RewriteRule ^moreprod/([^/]+)/$ moreprod.php?id=$1 [L]
RewriteRule ^moreprod/([^/]+)/([^/]+)/$ moreprod.php?id=$1&topid=$2 [L]
RewriteRule ^moreprod/([^/]+)/([^/]+)/([^/]+)/$ moreprod.php?id=$1&topid=$2&catid=$3 [L]
With this code, if you try (for example) to reach http://domain.com/new/moreprod.php?id=123&topid=456&catid=789 then you'll redirect to http://domain.com/new/moreprod/123/456/789/
Conclusion
You can now access your pages via clean urls like
http://domain.com/new/moreprod/123/ (id=123)
http://domain.com/new/moreprod/123/456/ (id=123 and topid=456)
http://domain.com/new/moreprod/123/456/789/ (id=123 and topid=456 and catid=789)
Resolved, just moved these lines to the bottom of .htaccess
RewriteEngine On
RewriteBase /new/
....
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/? [R=301,L]
.....
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)&topid=([^&\s]+)&catid=([^&\s]+)&cagid=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/%2/%3/%4/? [R=301,L]
RewriteRule ^moreprod/([^/]+)/$ moreprod.php?id=$1 [L]
.....
RewriteRule ^moreprod/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ moreprod.php?id=$1&topid=$2&catid=$3&cagid=$4 [L]
# THIS TO THE BOTTOM
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
I have pagination plugin in my CMS which produces ?pg=1 links. I want to redirect this url without this ugly postfix because without it CMS shows first page too.
So, i have url like http://site.ru/category/schock-crane/?pg=1 or http://site.ru/moyka/?type=granit&pg=1
I want to redirect such urls to http://site.ru/category/schock-crane/ and http://site.ru/moyka/?type=granit respectly.
I tried this .htaccess code
RewriteRule (.*)(&|\?)pg=1$ $1 [R=301,L]
I tried this regexp code at regexp trainers - it worked. But at live server no redirect happens.
Here is whole .htaccess file:
AddDefaultCharset Off
#DirectoryIndex index.php index.html
Options +FollowSymLinks
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# fix /?pg=1
RewriteRule (.*)(&|\?)pg=1$ $1 [R=301,L]
# fix .palitra-tab
RewriteCond %{REQUEST_URI} -tab$
RewriteRule (.*)/([0-9]*)/\.(.*)-tab?$ http://site.ru/redirect.php?id=$2 [R=301,L]
RewriteCond %{REQUEST_URI} ^/csss/.* [NC]
RewriteRule csss/(.*)\.css$ css.php?n=$1 [L]
#RewriteRule ^(.*)/csss/(.*) /test.php [L]
RewriteRule ^(.*)/base([0-9]+)/?$ $1?base=$2
#RewriteCond %{REQUEST_FILENAME} -f
#RewriteRule \.(gif|jpeg|jpg|png)$ /images/watermark/index.php [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*) index.php
RewriteCond %{HTTP:Authorization} !^$
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>
You need to use RewriteCond to examine the query string:
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)pg=1(&(.*)|$)
RewriteCond %1%4 (.*?)&?$
RewriteRule ^ %{REQUEST_URI}?%1 [R=301,L]
The second RewriteCond is just to remove a trailing &.
Maybe the missing ^ or / kills the redirect
# fix /?pg=1
RewriteRule ^(.*)(&|\?)pg=1$ /$1 [R=301,L]
or try
RewriteRule ^(.*)(&|\?)pg=1$ http://%{HTTP_HOST}/$1 [R=301,L]