I have the following url, and I simply want to hide the .php extension.
current url :
localhost/api.php/test/pickup/10000
new url
localhost/api/test/pickup/10000
I've been looking around for an answer, but all I can find is a way to remove the .php extension if the url ends with it.
So I wonder how do you remove the extension if the url is nested?
In the htaccess file in your document root, try:
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+api\.php([^\ \?]*)
RewriteRule ^ /api/%1 [L,R]
Assuming that when you go to localhost/api/test/pickup/10000 it actually resolves to what you want. Otherwise, you can try turning on multiviews:
Options +Multiviews
Related
I have about 100 urls which are like these:
http://example.com/en/contact-us
http://example.com/en/about-us
When the someone clicks on any of them, it should the same page but with a parameter that has been appended
for example :
http://example.com/en/contact-us?language=en
How would i go to solve this? I am tring to write something generic that will do the job for the 100 urls i have.
This is what i have got :
RewriteCond %{REQUEST_URI} /en/ [NC]
RewriteRule ^ %{REQUEST_URI}/?language=en
Internal redirection: URL in the browser doesn't change
RewriteEngine on
RewriteRule ^/?([a-z]+)/([^/]+)/? $1/$2?language=$1 [L]
External redirection: URL in the browser changes to new URL
RewriteEngine on
RewriteRule ^/?([a-z]+)/([^/]+)/? $1/$2?language=$1 [R=301,L]
Please try this
I think you may have forgotten to put a .php file extension at the end?
This will match any two-letter language folder followed by another directory, as long as there is no period.
RewriteRule ^/(\w\w)/([^/]+)/?$ $1/$2.php?language=$1
Be sure to test it with your URLs at regex101.
before to start asking i want to say that i tried to search everywere and i didn't found anything so...
My problem is that i want to have change first.html second.html and so on to first second without extensions and i use this:
Options +MultiViews
and now i have my files without extensions, now i want that when someone write first.html or second.html send it to error page, now my code is the following:
ErrorDocument 404 errore/errore.html
Options +MultiViews
Hope you help me.
Try adding:
RewriteCond %{THE_REQUEST} \ /+[^\?]+\.(html|php)
RewriteRule ^ - [L,R=404]
This rewrite rule (you'll need RewriteEngine On if you don't already have that in your htaccess file) matches direct requests to anything that ends with the extension .html or .php and flags the request as a 404 response using the R=404 rewrite flag.
We have some folders that includes some files without extension
for example :
/files/a0/ffa5301469e1fb84210e8b5a4a8f3ad3
/files/ff/ff957d05512ea1e71784e811ca45f1f9
/files/f6/f6ffa309ac3fe7fb5b01b07a37bb0d1d
as you see this files have not any extension , i want to add extension and change filename with rewrite rule :
for example :
REAL PATH : /files/a0/ffa5301469e1fb84210e8b5a4a8f3ad3
REWRITE : /files/a0/ffa5301469e1fb84210e8b5a4a8f3ad3/filename.zip
so i need "/files/a0/ffa5301469e1fb84210e8b5a4a8f3ad3" download as "filename.zip"
i tried a lot to edit .htaccess and rewrite rule but i can not succeed
how can i change filename and file extension with rewrite rule ?
You can try:
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+files/([a-f0-9]{2}/[a-f0-9]+)($|\ |\?)
RewriteRule ^ /files/%1/filename.zip [L,R]
RewriteRule ^files/([a-f0-9]{2}/[a-f0-9]+)/filename.zip$ /files/$1 [L]
in the htaccess file in your document root, but depending on the headers returned by the request, it may be telling the browser what type of attachment and filename it should be using, which means what the URL looks like will have no affect.
I have duplicate urls and i need to do some redirection in htaccess
Examples:
Original Urls are :
www.mywebsite.com/listofgames/pacman.html
www.mywebsite.com/listofgames/nintendo.html
www.mywebsite.com/listofgames/snake.html
I have about 1000 games name
Example of duplicate urls :
www.mywebsite.com/listofgames/1/pacman.html
www.mywebsite.com/listofgames/1521/pacman.html
www.mywebsite.com/listofgames/52154/pacman.html
www.mywebsite.com/listofgames/abc/pacman.html
www.mywebsite.com/listofgames/opq/pacman.html
www.mywebsite.com/listofgames/opq/1/2/35/pacman.html
www.mywebsite.com/listofgames/154/3562/snake.html
www.mywebsite.com/listofgames/2541/snake.html
www.mywebsite.com/listofgames/524/snake.html
www.mywebsite.com/listofgames/absc/gtar/15/nintendo.html
www.mywebsite.com/listofgames/nije/nintendo.html
I need to redirect them to original urls
So
www.mywebsite.com/listofgames/anynumber/mygamesname.html
www.mywebsite.com/listofgames/anyword/mygamesname.html
www.mywebsite.com/listofgames/anyword/anynumber/anyword/mygamesname.html
Must be redirected to
www.mywebsite.com/listofgames/mygamesname.html
You may try this:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/listofgames/.*/([^\.]+)\.html/? [NC]
RewriteRule .* listofgames/%1.html [R=301,L]
Redirects permanently
http://www.mywebsite.com/listofgames/any/number/of/folders/mygamesname.html
with or without trailing slash.
To:
http://www.mywebsite.com/listofgames/mygamesname.html
Effectively removing the segment path between /listofgames/ folder and the HTML file.
String listofgames and extension html are assumed to be fixed, while mygamesname is assumed to be variable.
The incoming URL structure has to be kept for the rule-set to work: Last string inside the URL must be the HTML file.
For silent mapping, remove R=301 from [R=301,L]
This seems like exactly what you would want to do with the htaccess rewrite rules. But I can't seem to get it to work properly.
I have this page on my site: http://wireie.gocactus.com/network_extensions.php
I want to rename it to: http://wireie.gocactus.com/transparent-ethernet-solutions
So this is the line I put in my htaccess file:
RewriteRule ^transparent-ethernet-solutions network_extensions\.php [NC]
Alrighty. Now if I go to /transparent-ethernet-solutions, it works great.
The problem is that, /network_extensions.php also still works great. So I'll want to rewrite that url with this line:
RewriteRule ^network_extensions\.php*$ /transparent-ethernet-solutions [R,NC]
Now it gives me an error message about too many redirects. If I add the second line without the first line, it changes the URL on the PHP link but gives me a 'page not found' error on the pretty link redirection.
My mind is blown. Can I have the URL rewritten without forwarding and have the new URL work without redirecting from the old one? I'm not sure if there's just some parameter I'm missing in the first line, or some combination of rules necessary.
This is the code that will be needed in your .htaccess:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^transparent-ethernet-solutions/?$ network_extensions.php [NC,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+network_extensions\.php\s [NC]
RewriteRule ^ transparent-ethernet-solutions [R=301,L]