my website URL accept double slashes too. for example when I put https://www.jamalacademy.com/class/9th-class it accept then if i put
https://www.jamalacademy.com//class/9th-class or https://www.jamalacademy.com///class/9th-class it accept too.. even if i add so many slashes it accept too..
Help me to get ride of this problem.
my current htaccess file is like:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+(.*?)/{2,}([^\s]*)
RewriteRule ^ %1/%2 [R=302,L,NE]
RedirectMatch 301 ^(.*)//+(.*)$ https://www.jamalacademy.com/$1/$2
RewriteEngine On
RewriteBase /
Options +FollowSymlinks
RewriteCond %{REQUEST_URI} //+
RewriteRule ^(.*) $1 [R=301,L]
RewriteEngine On
RewriteRule ^class/(.*)/?$ classes_list.php?get_page=$1 [NC,QSA]
thanks in advance.
You can use it like this:
RewriteEngine On
# remove multiple slashes from URLs
RewriteCond %{THE_REQUEST} //
RewriteRule ^.*$ /$0 [R=301,L,NE]
RewriteRule ^class/(.*?)/?$ classes_list.php?get_page=$1 [NC,QSA,L]
Make sure to clear your browser cache before testing this change.
Related
I got these URLs
https://www.adparch.com/vi/projects/common-wealth-bank/?pagenumber=2
https://www.adparch.com/projects/Technology--It/oppo?pagenumber=2
https://www.adparch.com/vi-VN/ky-thuat-cong-nghe?pagenumber=4
https://www.adparch.com/vi-VN/du-an?pagenumber=8
And They got 1 rule contains characters (?pagenumber). I want to redirect all to https://www.adparch.com/project/
I used .htaccess file for redirecting these URLs
RewriteEngine On
RewriteCond %{REQUEST_URI} ^.*$
RewriteCond %{QUERY_STRING} ^pagenumber=(.*)
RewriteRule ^(.*) /project [R=301,L]
But it seems not work.
Thank you so much
I do some cuts in your rules, please check:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} pagenumber=(.*)
RewriteRule ^(.*) /project/? [R=301,L]
</IfModule>
I want to redirect pages like:
/category-name/post-name.html?id=1234
To:
/category-name/1234-post-name.html
How can do this using htaccess?
What I have tried:
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^([^/]+)/([^.]+)\.html$ /$1/%1-$2\.html [L,R=301]
But it is a continuous redirect.
You can use these rules in your site root .htaccess:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+([\w-]+)/([\w-]+)\?id=([^\s&]+) [NC]
RewriteRule ^ /%1/%3-%2? [R=301,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^([\w-]+)/([^-]+)-([\w-]+)/?$ $1/$3?id=$2 [L,QSA]
Try this
Make sure the url is root url
Example:-
www.foo.com/category-name/post-name.html
It will only work if the project url is same as that of the above.
www.foo.com/blog/category-name/post-name.html
This won't work you need to update the RewriteBase url accordingly l.
This is the conditions
RewriteEngine On
RewriteBase /
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule here
RewriteRule ^category-name/([0-9]+)-post-name$ /category-name/post-name.html?id=$1 [L]
This should work..
I think I just need a second pair of eyes for this as I can't see why i'm getting a server error.
RewriteEngine On
RewriteRule ^Gig/([a-zA-Z0-9_-]+)$ gig.php
RewriteRule ^Gig/([a-zA-Z0-9_-]+)/$ gig.php
#allow non caps
RewriteRule ^gig/([a-zA-Z0-9_-]+)$ gig.php
RewriteRule ^gig/([a-zA-Z0-9_-]+)/$ gig.php
Edit:
I have now viewed the log and the reason is there are far too many internal redirects. I myself am not too competent at mod_rewrites etc so please have a look.
#redirect so home page shows /Home
Redirect /home.php http://localhost/Home
#add php extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Redirect /home.php http://localhost/Home
# redirect to .php-less link if requested directly
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteRule ^(.*)\.php /$1 [R=301,L]
#redirect www to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.^([a-zA-Z0-9_-]+)$ [NC]
RewriteRule ^(.*)$ http://^([a-zA-Z0-9_-]+)$1 [L,R=301]
#remove trailing slash
RewriteEngine on
RewriteRule ^(.*)/$ /$1 [L,R=301]
#allow artistprofile nice url
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_\-]+)/?$ artist_profile.php
#info nice url
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_\-]+)/[Aa]bout/?$ artist_about.php
#gigs nice url
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_\-]+)/[Gg]igs/?$ artist_gigs.php
#tracks nice url
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_\-]+)/[Tt]racks/?$ artist_tracks.php
#gig nice url
RewriteEngine On
RewriteRule ^[Gg]ig/([a-zA-Z0-9_\-]+)/?$ gig.php
That's all the rewrites in the .htaccess file
Edit:
The problem is the adding PHP extension part
#add php extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
I think its due to the ([a-zA-Z0-9_-]+) being after the file name.
You need to escape your - characters when they're inside brackets. You can also shorten your code to the following:
RewriteEngine On
RewriteRule ^[Gg]ig/([a-zA-Z0-9_\-]+)/?$ gig.php
# Escape it! ^^
Why can we shorten it like this?
[Gg] means "The character G or g"
/? means "/ repeated 0 or 1 time"
I'm hoping someone can assist me with a mod_rewrite rule to redirect dynamic urls pointing to "videos.php" on my server to the base url.
For example, I need to redirect 'website.com/1/music/various/videos.php?=1234'
to 'website.com/videos.php?=1234'
edit: I am looking for a dynamic solution. If a url is pointed to videos.php at any time, I need to do a 301 redirect to home directory. Ie if /1/home/music/videos.php?=1234 redirect to /videos.php?=1234, or /music/playlist/1234/videos.php?1432 to /videos.php?1432.
Create a .htaccess file and insert these lines:
RewriteEngine On
# Page moved permanently:
RewriteRule ^videos\.php\?\=([0-9]+)\.html$ /1/music/various/videos.php?=$1 [R=301,L]
When testing, leave out the R=301, part, or you'll only see cache contents for a long, long time. Add it when sure its working fine. Or use 302, which means temporarily.
Please check this:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/1/music/various/videos.php$
RewriteCond %{QUERY_STRING} (.+)$
RewriteRule ^(.*) /videos.php [R,QSA]
RewriteCond %{REQUEST_URI} ^/videos.php$
RewriteCond %{QUERY_STRING} !(.+)$
RewriteRule ^(.*) http://%{HTTP_HOST}/ [R=301]
If it's not work, then try this:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/1/music/various/videos.php$
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^(.*) /videos.php%1 [R]
RewriteCond %{REQUEST_URI} ^/videos.php$
RewriteCond %{QUERY_STRING} !(.+)$
RewriteRule ^(.*) http://%{HTTP_HOST}/ [R=301]
I would like to change urls from:
http://subdomain.domain.com/page/ to http://subdomain.domain.com/?page=pagename
and also:
http://domain.com/page/ to http://domain.com/?page=pagename
though haven't had much success.
Here is my htaccess file so far [updated]
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# Remove 'www'
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Add slashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://resolutiongaming.com/$1/ [L,R=301]
# Subdomain redirect
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$1 [R=301,L]
# Search engine optimization
RewriteRule ([a-zA-Z]+)/$ ?page=$1
I used RewriteRule ^([a-zA-Z]+)/$ ?page=$1 which seemed to work for the domain url but not the subdomain. Any help would be appreciated.
Actually had to do something like this recently. Try this for your Subdomain redirect block:
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$2 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$2 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$2 [R=301,L]
Or maybe this; note the change from $2 to $1:
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$1 [R=301,L]
EDIT: Or Maybe try this. Note that you need to capture two parts of the URL to rewrite as you are explaining. Each item in parenthesis ( and ) corresponds to a string in the rewrite. Try this. Using your nicer regular expression RewriteRule as you mention in the comments:
RewriteRule ^([a-zA-Z]+)/(.*)$ /$1/$2 [R=301,L]
Or maybe this:
RewriteRule ^([a-zA-Z]+)/(.*)$ /$1/page=$2 [R=301,L]
So it was an easy fix really. I basically put a .htaccess file in each subdomain directory that looks like this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# Search engine optimization
RewriteRule ([a-zA-Z]+)/$ ?page=$1
Hope this helps someone. :D