I need your precious help.
I have an url:
http://domain.com/v/12345
My ht access is set to pass 12345 to php script like:
htaccess:
RewriteRule ^v/([a-zA-Z0-9_-]+)$ /script.php?v=$1 [L]
script php:
http://domain.com/script.php?code=12345
and works perfectly but.. and there is a but, I would write my url so:
http://domain.com/12345/my-dog-is-very-fat
can you help to change my htaccess to works so? Because if I use /my-dog-is-fat or just / I get an 404 error.
I try to explain better:
I would share link with seo keywords in the url, example
mydomain.com/alphanumericCode/thi-is-my-dog-article
where alphanumericCode is get of myscript.php?V=
This is my htaccess:
RewriteEngine On
RewriteRule ^view/([a-zA-Z0-9_-]+)$ /view.php?v=$1
RewriteRule ^folder/([a-zA-Z0-9_-]+)$ /filefolderlist.php?f=$1
RewriteRule ^home$ /index.php [L]
RewriteRule ^report$ /report.php [L]
RewriteRule ^play/([a-zA-Z0-9_-]+)$ /play.php?v=$1 [L]
###Added by anubhava
RewriteRule ^v/([\w-]+)/?$ /script.php?v=$1 [L,QSA]
RewriteRule ^([0-9a-z]+)/.+$ /script.php?v=$1 [L,QSA,NC]
##end
RewriteRule ^privacy-policy$ /privacy.php [L]
ErrorDocument 404 404.php
You can have a new rule for the new URI scheme:
RewriteEngine On
RewriteRule ^v/([\w-]+)/?$ /script.php?v=$1 [L,QSA]
RewriteRule ^([0-9a-z]+)/.+$ /script.php?v=$1 [L,QSA,NC]
Related
I need the url
from
localhost/project/category?c=electronics
to
localhost/project/category/electronics
I have tried
RewriteRule ^category/([^/\.]+)?$ /category.php?c=$1 [L]
RewriteRule ^category/+?$ /category.php?c=$1 [NC,L]
With your shown samples and attempts please try following htaccess rules. Please do clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /
##External redirect to url change in browser.
RewriteCond %{THE_REQUEST} \s/(project/category)\.php\?c=(\S+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Internal rewrite to category.php in backend.
RewriteCond %{DOCUMENT_ROOT}/$1/$2.php -f
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ %{DOCUMENT_ROOT}/$1/$2.php?c=$3 [QSA,L]
RewriteEngine on
RewriteBase /
RewriteRule ^project/category/([0-9a-z]+)$ /project/category?c=$1 [L]
Why is "project/" missing in your original try ?
You have to specify the full path.
You can try this simple rewriteRule wich should works.
My .htaccess has the following code :
RewriteRule ^([A-Z]+)$ listings/$1 [R=301]
RewriteRule ^listings/([A-Z]+)/?$ listings_state.php?state=$1 [NC,L]
With this rule I am trying to achieve 301 redirect from spb.com/test_1/XY to spb.com/test_1/listings/XY
However, it is redirecting to spb.com/path/to/test_1/in_server/test_1/listings/CT
and I tried changing .htaccess to as follows:
RewriteRule ^([A-Z]+)$ /listings/$1 [R=301]
RewriteRule ^listings/([A-Z]+)/?$ listings_state.php?state=$1 [NC,L]
RewriteRule ^/([A-Z]+)$ /listings/$1 [R=301]
RewriteRule ^listings/([A-Z]+)/?$ listings_state.php?state=$1 [NC,L]
RewriteRule ^/([A-Z]+)$ /listings/$1 [R=301]
RewriteRule ^/listings/([A-Z]+)/?$ listings_state.php?state=$1 [NC,L]
Nothing seems to work.
Please guide me in this regard. Thank you community :)
Could you please try following, based on your shown samples only. Please make sure you clear your browser cache before testing your URLs
RewriteEngine ON
RewriteRule ^([A-Z]+)/?$ /test_1/listings/$1 [R=301]
RewriteRule ^test_1/listings/([A-Z]+)/?$ listings_state.php?state=$1 [NC,L]
here is my rules for htaccess file.
RewriteRule ^admin/?$ admin/index.php
RewriteRule ^cart/([0-9]+)/?$ cart.php?t=$1
RewriteRule ^register$ register.php
RewriteRule ^login$ login.php
RewriteRule ^forgot-password$ forgot_password.php
RewriteRule ^terms-and-conditions$ terms_and_conditions.php
RewriteRule ^request-consideration$ request_consideration.php
RewriteRule ^([a-z0-9\-]+)/?$ products.php?cid=$1
RewriteRule ^([a-z0-9\-]+)/([a-z0-9\-]+)/?$ products.php?cid=$1&scid=$2
RewriteRule ^([a-z0-9\-]+)/([a-z0-9\-]+)/([a-z0-9\-]+)/?$ product_details.php?cid=$1&scid=$2&id=$3
ErrorDocument 404 /error_404.php
Now the problem is when i try to redirect it say www.example.com/cart/123 it goes products.php page. I want to restrict the url www.example.com/cart/123 only. so www.example.com/cart or www.example.com/cart/abc will redirect to error_404 page. same for other also like register, login etc.
Any help would be appreciated. Thanks in advance.
Based on you comments, you want to redirect the uri to 404 page if /cart or /cart/abc is requested, you can use the following rules. Put this at the top of your htaccess before other RewriteRules
RewriteEngine on
RewriteRule ^cart/?$ - [R=404,L]
RewriteRule ^cart/[A-Za-z]+/?$ - [R=404,L]
I have a link
http://www.mydomain.com/place/index.php?slug=antalya-hotels
and i want to write this like
http://www.mydomain.com/place/antalya-hotels.html
I have tried this
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /place/index.php?slug=$1 [L]
Bu didnt work. how we can do.
You can use:
RewriteEngine On
RewriteRule ^place/([^.]+)\.html$ /place/index.php?slug=$1 [L,QSA,NC]
OR
RewriteRule ^([^/]+)/([^.]+)\.html$ /$1/index.php?slug=$2 [L,QSA,NC]
I am trying to rewrite from
mysite.com/pokerbono/xyz
to
mysite.com/pokerbono.php?id=XYZ
Here is the code I added in the .htaccess:
#### Affiliate Links
RewriteRule ^pokerbono/([a-zA-Z0-9_-]+)$ pokerbono.php?id=$1 [L]
What is wrong with this rule? I tried like 100 variations and always receive a 404.
I tried each and every variation right now I have in my .htaccess the following rows:
RewriteRule ^pokerbono/([a-zA-Z0-9_-]+)$ pokerbono.php?id=$1 [L]
RewriteRule ^pokerbono/([a-zA-Z0-9_-]+)/$ pokerbono.php?id=$1 [L]
RewriteRule ^/pokerbono/([a-zA-Z0-9_-]+)$ pokerbono.php?id=$1 [L]
RewriteRule ^/pokerbono/([a-zA-Z0-9_-]+)/$ pokerbono.php?id=$1 [L]
RewriteRule ^/pokerbono/([a-zA-Z0-9_-]+)$ /pokerbono.php?id=$1 [L]
RewriteRule ^/pokerbono/([a-zA-Z0-9_-]+)/$ /pokerbono.php?id=$1 [L]
Try including slashes on the front:
RewriteRule ^/pokerbono/([a-zA-Z0-9_-]+)$ /pokerbono.php?id=$1 [L]
UPD:
This works in my environment:
RewriteEngine On
RewriteRule ^qwe/([-_a-zA-Z0-9]*)$ qwe.php?id=$1 [L]
I had to disable Multiviews, now it is working fine :)