localhost, xampp, win 7
site root folder is s02, so all relevant files, including .htaccess is under this folder.
links like this work fine:
http://localhost/news/s02/view.php?art=160915142500&title=blue-sky
I want the following computed url
http://localhost/articles/160915142500/blue-sky
.htaccess
RewriteEngine on
RewriteBase /
RewriteRule ^articles/([0-9]+)/([a-zA-Z-_]*)$ view.php?art=$1&title=$2 [NC,L]
result - error 404
httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so - uncommented
AllowOverride All
.htaccess (test) - this works:
RewriteEngine on
RewriteRule ^ http://example.com/? [L,R]
phpinfo();
mod_rewrite is under Loaded Modules
Any help?
Try with below rule, we are telling apache that incoming uri is not a file or directory.
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^articles/([0-9]+)/([a-zA-Z-_]*)$ /news/s02/view.php?art=$1&title=$2 [NC,L]
Place .htaccess file into the root folder i.e. htdocs for xampp (I guess). The .htaccess file should be like this.
RewriteEngine on
RewriteBase /
RewriteRule ^articles/([0-9]+)/([a-zA-Z-_]*)$ news/s02/view.php?art=$1&title=$2 [NC,L]
Related
i want to change my permalink example www.testing.com/1234/"titlename" instead of www.testing.com/1234/, how to do i change it through .htaccess? Below are my .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /clients/ohmynews/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?article/([a-zA-Z0-9_-]+)$ detail.php?did=$1
RewriteRule ^/?([a-zA-Z0-9_-]+)$ listing.php?lid=$1
RewriteRule ^/?search/([a-zA-Z0-9_-]+)$ search.php?keys=$1
DirectoryIndex index.php
ErrorDocument 404 http://wipstage.com/clients/ohmynews/web/
</IfModule>
Include this line into your htaccess file:
RewriteRule ^([0-9]+)/([A-Za-z0-9._-]+)/?$ detail.php?id=$1&title=$2
As i do not know your actual running file path, so make sure you put your original running file path in my code.
Or let me know your file name with location, i will edit my answer.
In the past, I have got this working no problems at all, but for some reason on my new server I just can't get it to work.
I have the following .htaccess file in the root of my application
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I have also enabled mod_rewrite and have confirmed this with php_info()
my site is located at /var/www/html/test
Is it possible that although mod_rewrite is enabled that it is not working and if so, how can I test it?
On some server implementations, you'll need to wrap it within <IfModule> tags.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Also check your httpd.conf file to ensure it has:
Options FollowSymLinks
AllowOverride All
It'd also be worth checking to makesure the .htaccess file isn't being overridden by another .htaccess file.
A simple way to test if .htaccess is working
Simply put the following in your .htaccess file:
deny from All
What this does is deny access to your site from everyone. If you are presented with a 403 forbidden when trying to access the site - the .htaccess file is being included. If not - see above.
I use this on my codeigniter setup
RewriteEngine on
# prevent these directories from hitting CI
RewriteCond $1 !^(index\.php|images|assets|robots\.txt|crossdomain\.xml)
# route everything else to the index.php
RewriteRule ^/(.*)$ /index.php/$1 [QSA]
(my setup is done in the virtualhost of .conf and not in .htaccess, though they are usually about the same configuration)
So, I moved the website.com to subdomain.website.com. The .htaccess file is located in the website.com/subdomain/ folder, it should work but it's not working.
Error message: The requested URL /title-123 was not found on this server.
Basically what it does is translates the website.com/product.php?id=123&title=hello to website.com/hello-123
The error is produced when trying to access subdomain.website.com/title-123
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/product\.php\?id=([0-9]+)&title=([^\s&]+)\s [NC]
RewriteRule ^ %2-%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+?)-([0-9]+)$ product.php?id=$2&title=$1 [L]
</IfModule>
Anyone knows how to fix this? Thanks!
After a lot of research and debugging of apache conf files and receiving expert's assistance i managed to fix it removing completely the .htaccess file and adding the rewrite rules in the apache VirtualHost directly.
I've tried pretty much everything i can think of, I've basically moved from Mac OS to Windows OS webserver with my project (testing essentially). When i access any other page from my server I get the "Page Not Found" error, however it works if i add index.php/location, anyway here is some of my settings:
Initially i have checked if mod_rewrite is enabled by adding this: in_array('mod_rewrite', apache_get_modules()) to a conditional statement which responded as true so i know mod_rewrite is in face enabled.
Here is my .htaccess file which is located in the main directory of my project (with index.php):
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
Have also tried as RewriteRule ^(.*)$ index.php/$1 [L] and written it outside the <ifModule> tags.
Here are some of my codeigniter settings:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
I have also tried including the index.php in the index_page and tried REQUEST_URI for the uri_protocol and nothing seems to be working.
Sidenote: It runs perfectly on my mac and linux (Raspberry Pi).
Can you suggest any alternative methods or spot something I've missed.
EDIT:
httpd.conf i have done the following
<directory />
Options All
AllowOverride All
</directory>
ALL instances of AllowOverride None have been changed to AllowOverride All
The following has been uncommented/enabled:
LoadModule rewrite_module modules/mod_rewrite.so
Do not touch your default .htaccess file in php.
Make a new file in your codeigniter root directory named ".htaccess"
Paste below code into this new file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /leo/index.php/$1 [L]
Save it and it should work now.
I have the following URL on my localhost:
http://localhost/?cmd=causeListByCourtName
http://localhost/?cmd=here could be any other page name
I have tried to rewrite the URL like =
http://localhost/page/causeListByCourtName
I have tried this:
RewriteEngine On
RewriteRule ^pages/(.+)/?$ .+/?cmd=$1 [NC,L]
# Handle pages requests
But it do nothing. I am using XAMPP on my windows 7.
in my httpd.conf :
LoadModule rewrite_module modules/mod_rewrite.so
is already enabled. What I am doing wrong?
You need to also make sure you changed AllowOverride None to AllowOverride All in your httpd.conf file wherever you find it.
Try doing it this way.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/(.+)/?$ /?cmd=$1 [NC,L]
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^page/(.*)$ index.php?cmd=$1 [L]
This in case you use index.php as your default page. You can cut down the index.php from the front