If 'localhost/a/something' is the url, the .htaccess rewrites it to 'localhost/a/1.php?food=something'
If I type in 'localhost/a/something something' it gives me a 404 error.
My current .htaccess:
RewriteEngine on
RewriteBase /a/
RewriteRule ^([A-z]+)$ 1.php?food=$1 [L]
How can I 'localhost/a/something something' to 'localhost/a/1.php?food=something+something'?
Please have a look at:
How to redirect %20 or White space automatically to + or - with htaccess?
This seems to do what you are trying to do...
Try this rule in your .htaccess:
RewriteRule ^article/with\ 1.php$ /food/1.php [R=301,L]
Related
I have the URL of:
https://test.co.uk/blog/?p=308
And I want to redirect it to:
https://test.co.uk/category/article
How do I do this in an .htaccess file? I tried a regular 301 redirect in the .htaccess file, but it doesn't work because of the ? and = symbols.
I got the answer here... https://www.301-redirect.online/htaccess-rewrite-generator
It was...
RewriteEngine on
RewriteCond %{QUERY_STRING} ^p\=308$
RewriteRule ^blog/$ https://test.co.uk/category/article/? [R=301,L]
I've been pulling my hair out trying to get a URL rewrite rule to work using .htaccess. Mod_rewrite is enabled and I have managed to get a 301 redirect to work (from /beta to /Beta/) so I know the .htaccess is able to work.
Basically I'm trying to get /Beta/Page.php?id=page&tab=services&tabid=tab1 to become /page/services (and ideally leave out the tabid if it's not going to break the site removing it).
The code I'm working with currently is:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/Beta/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ /Beta/Page.php?id=$1&tab=$2&tabid=$3
redirect 301 /beta http://www.example.com/Beta/
Any help would be gratefully received.
Remove the leading slash:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(Beta)/[^.]+\.php\?id=([^&]+)&tab=([^\s&]*)&tabid=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/%3/%4? [R=302,L]
RewriteRule ^Beta/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ /Beta/Page.php?id=$1&tab=$2&tabid=$3 [L,QSA]
This will externally redirect:
/Beta/Page.php?id=page&tab=services&tabid=tab1
to
/Beta/page/services/tab1
and rewrite same URI internally.
Also .htaccess is per directory directive and Apache strips the current directory path (thus leading slash) from RewriteRule URI pattern.
I have this htaccess file:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+:/.)$ result.php?u=$1
RewriteRule ^([a-zA-Z0-9]+:/.)/$ result.php?u=$1
And what i'm trying to do is, rewrite http://example.com/http://google.com to http://example.com/result.php?u=http://google.com but I just get a "The requested URL was not found on this server"
Try this:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9:/\.]+)$ http://example.com/result.php?u=$1
Trying to do some 301 rewrites but an urls string is appended..
I think this is happening because I'm using a SEO rewrite and 301 redirect on top? Any suggestions on how to fix this would be highly appreciated!
The problem is:
This URL: domain.nl/meubels/Tafels/Theetafels-en-wijntafels/
Should be rewritten to: domain.nl/meubels/tafels/theetafel-wijntafel/
But it's rewritten to: domain.nl/meubels/tafels/theetafel-wijntafel/?activetab=Tafels&cat=Theetafels-en-wijntafels
Where this should not be added to the URL: ?activetab=Tafels&cat=Theetafels-en-wijntafels
My htaccess file:
ErrorDocument 404 /error404.php
RewriteRule ^meubels/$ product-listing.php?show=home
RewriteRule meubels/(.*)/(.*)/(.*)/$ product-listing.php?activetab=$1&cat=$2&open=$3
RewriteRule meubels/(.*)/(.*)/$ product-listing.php?activetab=$1&cat=$2
RewriteRule product/(.*)/$ product-detail.php?id=$1
RewriteRule info/(.*)/$ text-page.php?show=$1
RewriteRule info/(.*)/$ text-page.php?show=$1
# DirectoryIndex product-listing.php?cPath=32
Redirect 301 /meubels/Tafels/Theetafels-en-wijntafels/ /meubels/tafels/theetafel-wijntafel/
RewriteRule ^meubels/Tafels/Theetafels-en-wijntafels/ http://domain.nl/meubels/tafels/theetafel-wijntafel/ [R=301,L]
And like #Liam Bailey said, it should be on top, before other rewrite rules.
.htaccess works in vertical order down the page, so if you move your 301 to above the rewrite rules for meubels, then it will redirect and then show the parametised meubels page on the friendly url.
ErrorDocument 404 /error404.php
Redirect 301 /meubels/Tafels/Theetafels-en-wijntafels/ /meubels/tafels/theetafel-wijntafel/
RewriteRule ^meubels/$ product-listing.php?show=home
RewriteRule meubels/(.*)/(.*)/(.*)/$ product-listing.php?activetab=$1&cat=$2&open=$3
RewriteRule meubels/(.*)/(.*)/$ product-listing.php?activetab=$1&cat=$2
RewriteRule product/(.*)/$ product-detail.php?id=$1
RewriteRule info/(.*)/$ text-page.php?show=$1
RewriteRule info/(.*)/$ text-page.php?show=$1
# DirectoryIndex product-listing.php?cPath=32
The first time it looks at htaccess it will redirect on the 301 straight, then the second time it will skip that and serve the rewrite. If that doesn't work try RewriteEngine On above your rewrite rules.
I have already configured my apache(mod_rewrite,alias,allowOverride), and I am trying to rewrite
http://localhost/b33m/view_blog_details.php?post_id=4
To
http://localhost/b33m/blogs/4
so that user can simply type in the second url and it would work. But I am getting a 404 not found error.
I am using WAMP on XP, and my .htaccess is in www->b33m
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^b33m/blogs/([^/]*)$ /b33m/view_blog_details.php?post_id=$1 [L]
Try:
RewriteEngine On
RewriteRule ^blogs/(\d+)$ view_blog_details.php?post_id=$1 [L]
Note the / in the beginning of each URL have been omitted.
Try the following:
EDIT: I updated the code which hopefully will work better
RewriteEngine On
RewriteBase /b33m
RewriteRule ^blogs/([0-9]+)$ /view_blog_details.php?post_id=$1 [L]
Since you expect an id I'd rather use:
Moreover shouldn't you put a trailing slash?
RewriteEngine On
RewriteRule ^/b33m/blogs/(\d+)$ /b33m/view_blog_details.php?post_id=$1 [L]
Try adding this in your hosts file:
www.localhost.com 127.0.0.1
.htaccess sometimes doesn't like localhost