I have searched around and tried a few different things, with no luck.
I am trying to load this page http://SERVERNAME.com/get.php when I use the url http://SERVERNAME.com/get
Here is what I have in my htaccess now:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
I have tested to make sure my htaccess file is being read by intentionally breaking it and getting a 500 error.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{THE_REQUEST} ^(?:GET|POST)\ /.*\.php\ HTTP.*$ [NC]
RewriteRule ^(.*)\.php$ $1 [R=301,L]
Related
Good Morning,
I have documents within the structure of my website, which are accessed with the following url format:
http://example.com/docs/files/123/mydoc.pdf
http://example.com/docs/files/475/otherdoc.pdf
I want when a url of the above type is accessed, it is renamed with the following format:
http://example.com/123/mydoc
http://example.com/475/otherdoc
I have the following rules in the htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteRule ^/docs/files/([0-9]+)/([a-zA-Z0-9-]+)\.([a-zA-Z-]+) /$1/$2 [QSA,L]
</IfModule>
If I type in the browser
http://example.com/docs/files/123/mydoc.pdf
It doesn't change the url to
http://example.com/123/mydoc
What am I doing wrong?
Thanks
You may try these rules in your site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+files/(\S+)\.pdf[?\s] [NC]
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/files/$1.pdf -f
RewriteRule ^(.+?)/?$ files/$1.pdf [L]
With your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s(/files/.*)\.pdf\s [NC]
RewriteRule ^ http://%{HTTP_HOST}%1 [R=301,NE]
RewriteRule ^(.*)/?$ files/$1.pdf [L]
I have made clean urls in .htaccess file, but after that I dont get Access to a spesific folder. How can I get Access to /folder/?
.htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9]+)$ index.php?side=$1 [QSA]
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?side=$1 [QSA]
RewriteRule ^([a-z]+)\/([a-zA-Z0-9]+)\/?$ index.php?side=$1&id=$2 [NC]
RewriteRule ^rss/feed/([a-zA-Z0-9]+)\/?$ index.php?side=feed&id=$1 [NC]
You can use the following :
Options +FollowSymLinks
RewriteEngine On
##-if an existent dir or file is requested, serve it immideatly##
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
########
RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?side=$1 [QSA,L]
RewriteRule ^([a-z]+)/([a-zA-Z0-9]+)/?$ index.php?side=$1&id=$2 [NC,L]
RewriteRule ^rss/feed/([a-zA-Z0-9]+)\/?$ index.php?side=feed&id=$1 [NC,L]
I have web hosting in GoDaddy.
Call it: http://example.com
I have this below .htaccess
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ /$1.php [L,QSA]
What I want is, when I open http://example.com/about.php will be http://example.com/about <-- without .php extension.
I tried to upload it to the hosting, but it always show error the file not found.
*Are we need to wait for long time to godaddy update the .htaccess?
To remove .php from pages:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php [NC]
RewriteRule ^ %1 [R=301,L,NC,QSA]
and then, internal redirection to php pages:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f [NC]
RewriteRule ^.*$ $0.php [QSA,L]
Currently, I'm using the below htaccess code to load http://www.domain.com/folder/file.php from http://www.domain.com/file, removing the folder name "/folder/", and the file extension ".php", from the URL.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/folder%{REQUEST_URI}\.php -f [OR]
RewriteCond %{DOCUMENT_ROOT}/folder%{REQUEST_URI} -d
RewriteRule ^(.*)$ /folder/$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Now, I'm trying to do almost the same, but with a file that is stored in a subfolder.
So, in other words, I want to call http://www.domain.com/folder/subfolder/file.php from http://www.domain.com/subfolder/file
In this case, hiding the extension file is not a problem as the 2 last lines from the code above works globally, the issue is with the Rewriting which doesn't work simply by adding the 'subfolder' name. I thought this was going to work, but it wasn't:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/folder/subfolder%{REQUEST_URI}\.php -f [OR]
RewriteCond %{DOCUMENT_ROOT}/folder/subfolder%{REQUEST_URI} -d
RewriteRule ^(.*)$ /folder/subfolder/$1.php [L]
I appreciate any help.
Replace both of your rules with this:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/folder/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /folder/$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
I'm trying to have clean URLs, here is my code:
Options -Multiviews -Indexes +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteEngine ON
RewriteRule ^([0-9a-z\-\_]+)?$ profile.php?q=$1 [QSA,L,NC]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
ErrorDocument 404 /page/error?q=aqw
The only issue is that, i can not call a directory, i have to specify the file name, for exemple:
Help //this is not working
//This is working
So how can i fix that, thanks
Looking at your rules I think your first rule is redundant that you can remove.
Try this in your document root:
RewriteEngine On
RewriteBase /
ErrorDocument 404 /error?q=aqw
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]