.htaccess not working (mod_rewrite)
In my case, I changed in httpd.conf:
AllowOverride None
to
AllowOverride All
and it works.
url rewrite not working .htaccess
Your problem is that the line before the last one is defined as the last one so your rule must be above that RewriteConditions. Better use this rule set:
RewriteRule ^/?inbox/(\d+)$ /inbox.php?pg=$1 [QSD,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [QSA,L]
I added your needed prefix which you missed and made it mandetory that after that numbers will follow (at least one).
.HTACCESS Apache Mod_Rewrite not working
No need to write RewriteBase /
Use below htaccess.
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
# add / before index.php
Hope it will work :-)
Simple rewrite rule is not working on Apache server
With your shown samples, please try following htaccess rules file. Place your https and www implementing rules at top of your file.
Make sure your htaccess and index.php files are in root directory.
Please make sure to clear your browser cache before testing your URLs.
RewriteEngine On
# Redirect from HTTP to HTTPS
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^test/?$ index.php [NC,L]
Change the structure of htaccess as follows with your shown samples apart from few minor other changes in htaccess(like fixed regex for redirection, used NE
flag in redirection, combined Rules for https and www redirects etc; to improve your rules file)
| .htaccess
| www
| -- index.php
| -- .htaccess (new)
apache mod_rewrite not working with .htaccess file
Not sure if this is the cause of your problems, but you shouldn't mess with the
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
line, and it should be something like:
<Directory />
Options FollowSymLinks
AllowOverride None
Deny from all
</Directory>
You should add the directory of your document root as a different container:
<Directory /var/www/html/>
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
Mod-Rewrites Not Working in htaccess with PHP
You don't actually state what is happening (errors? response codes? etc.), however, there are a few issues with your config with respect to extensionless URLs.
Options +Indexes +Includes +FollowSymLinks +MultiViews
You are explicitly enabling MultiViews
in your server config, however, this is going to conflict with the mod_rewrite directives in .htaccess
that attempt to append the file extension. MultiViews
needs to be disabled. eg. -MultiViews
(not +
).
However, you are also enabling directory indexes (Indexes
) and server-side-includes (Includes
) for some reason? Is this intentional? And, rather confusingly, you are setting different options for your www subdomain than for the domain apex?
In the vHost container it is often preferable to state just the options needed. For example:
Options FollowSymLinks
(This naturally disables MultiViews by not setting it.)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
These mod_rewrite directives in .htaccess
to append the file extension are not strictly correct. Whilst they may work for your "valid" URLs, a malicious user could construct a URL of the form /index/<anything>
that would otherwise map to /index.php
, to trigger a rewrite-loop (500 Internal Server Error)*1.
These should be written like this instead (assuming your .htaccess
file is in the document root) to avoid this vulnerability:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule (.*) $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule (.*) $1.html [L]
The literal dot does not need to be escaped in the TestString (first argument to the RewriteCond
directive) since this is a "string", not a regex. The NC
flag is not required here.
If your URLs themselves don't contain "file extensions" then you can optimise the above by not testing URLs that already look like they have a file extension. For example:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule !\.\w{2,4}$ %{REQUEST_URI}.php [L]
The negated regex !\.\w{2,4}$
only matches URLs that don't contain - what looks like - file extensions. A file extension in this context is a sequence of 2 to 4 letters/digits at the end of the URL-path, preceded by a dot.
*1 See my answer to the following ServerFault question that goes into more detail regarding the potential rewrite-loop and resulting 500 error response:
- https://serverfault.com/questions/989333/using-apache-rewrite-rules-in-htaccess-to-remove-html-causing-a-500-error
apache mod_rewrite is not working or not enabled
Try setting: "AllowOverride All".
Related Topics
Replacing Environment Variables in a Properties File
Convert Utf8 to Utf16 Using Iconv
Sighup for Reloading Configuration
Google-Chrome Failed to Move to New Namespace
Add User to Group But Not Reflected When Run "Id"
How to Make Sure the Numpy Blas Libraries Are Available as Dynamically-Loadable Libraries
Is It Possible That Linux File Descriptor 0 1 2 Not for Stdin, Stdout and Stderr
How to Get Started Developing on *Nix
Spidev Linux Driver on Intel Atom Board
Tilde Expansion in Environment Variable
Linux Kernel System Call Returns -1 Instead of {-1, -256}
The Irq in Kernel Function Asm_Do_Irq() Is Different from the One I Request in Module
What Does Double Slash // in 'Cd //' Mean in Linux
How to Exclude Absolute Paths for Tar
Does Creating a Symbolic Link to Another Symbolic Link Have Any Side-Effects
Bash: Call Script with Customized Keyboard Shortcuts
Combine a Shell Script and a Zip File into a Single Executable for Deployment