Remove php extension remove then I add / in url [duplicate] - .htaccess

This question already has answers here:
Remove .php extension with .htaccess
(17 answers)
Removing .php file extension with .htaccess file
(5 answers)
How to get rid of .php extension in .htaccess
(1 answer)
Remove .PHP File Extension in URL
(4 answers)
Closed last month.
www.example.com/about.php
url i want to change this url
www.example.com/about/
I want to .php extension remove then I add / in url

Related

.htaccess regex redirect avoid by file type

I have two URL conditions and I wanted to redirect them like this:
https://www.example.com/feeds/4aceXy to https://www.example.com/direct_feed/4aceXy
Now the problem is, I am also using the URL for an older link like this one:
https://wwww.example.com/feeds/5bdb39711b41d479273e678a6f356603d7109ffc.xml
I wanted to avoid redirect with .xml extension here is my current redirect:
RewriteRule feeds/(.*)?$ https://wwww.example.com/direct_feed/$1 [QSA,L]
It works fine but I don't want to redirect it with .xml based URL.
My question is - is there a condition that can help me to avoid the rewrite if a parameter contains .xml in regX (.*)?$
You can use a negative lookbehind:
RewriteRule feeds/(.*)?(?<!\.xml)$ https://wwww.example.com/direct_feed/$1 [QSA,L]

disable .php and .html files from my directory listing?

How can I disable .php and .html files from my directory listing?
When someone visit my directory
http://example.com/dir
All other files except .php and html should be listed.
Add the following line to your .htaccess file
IndexIgnore *.html *.php
This tells the Apache web server to list all files except those that end with .php and .html .
If you want to disable all files and directories form listing ,Add this line to your .htaccess
IndexIgnore *
The wildcard '*' means it will not display any files

Is it possible to wildcard a filename string to password protect a file with htaccess?

Example: wp_file*.log -- what that should do is to password protect every file whose filename start with wp_file and ends with .log -- for example wp_file-22.log and wp_file_randomfile.log.
Possible?
The way I would make this, is by adding a rewrite rule for those files, redirect to some PHP file with the origional request in the GET. The PHP file can than show a password box and eventually the content of the log file once logged in.
RewriteEngine On
RewriteRule wp_file(.*)\.log /somePHPfile.php?logFile=wp_file$1 [L]
(not tested)
If you dont need access to the log files via your website (but use e.g. ftp), than you can rewrite the requests to those files to another page
RewriteEngine On
RewriteRule wp_file(.*)\.log /index.php [L]

Case-insensitive htaccess 301 [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have about 300 redirects in the following format
Redirect 301 /post/My-Blog-Post.aspx https://www.example.com/blog/a-new-post/
That works great except the redirects are case sensitive and going to /post/my-blog-post.aspx doesn't redirect.
There isn't a pattern for the old URL to new URL so this would likely have to be a flag for every redirect.
How can I get the URL to redirect no matter the case?
Don't think there's a way to make the Redirect directive (part of mod_alias) case insensitive, but there's a mod_rewrite flag that you can use. You'll need to change all of your redirects from this:
Redirect 301 /post/My-Blog-Post.aspx https://www.example.com/blog/a-new-post/
to:
RewriteRule ^/?post/My-Blog-Post.aspx$ https://www.example.com/blog/a-new-post/ [L,R=301,NC]
Note the NC flag, meaning "no case". This will match any URI that looks like /post/my-blog-post.aspx and ignores case, and redirects it to https://www.example.com/blog/a-new-post/.
However, if you want to make "My-Blog-Post" a variable of "a-new-post", I mean if you want /post/My-Blog-Post.aspx to be redirected into /blog/a-new-post/ either /post/this.aspx into /blog/this/ or /post/that.aspx into /blog/that/ or even /post/anything.aspx into /blog/anything/, you can try to use this code in you .htaccess hidden file:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^post/([a-z0-9-_]+).aspx$ /blog/$1/ [R=301,NC]

want to replace .php?url= this part by / from my url using .htaccess

In my website there is a link like this
http://backlinks.cheapratedomain.com/backlinks.php?url=emobileload.com
for better SEO I want to make it like this
http://backlinks.cheapratedomain.com/backlinks/emobileload.com
just want to replace '.php?url=' by '/'
My question is how can i do this by editing my .htaccess file ?
If it's only for that one URL, then you could try this:
RewriteRule ^backlinks/([a-zA-Z0-9\.\-]*)$ backlinks.php?url=$1 [L]
So requested URLs like http://backlinks.cheapratedomain.com/backlinks/domain.com will be redirected to http://backlinks.cheapratedomain.com/backlinks.php?url=domain.com

Resources