I have a file called car-details.php it takes the variable id= with the cars registration details in order to populate the page.
I can currently get this rewrite rule working
RewriteRule ^car-for-sale/(.*) car-details.php?id=$1 [NC,L]
But I would like to have a url like
/GV09LBX/Ford-car-something-etc
but for some reason I just can't get the second part of the url to work. I followed some guides in order to add a second part to the url example below
RewriteRule ^car-for-sale/(.*)/(.*) car-details.php?id=$1&something=$2 [NC,L]
Where something=$2 isn't even used by the car-details.php file but I would just like to have the car name in the url for seo purposes. Whenever I've tried to add a second forward slash the rewrite rule stops working. Any help?
full htaccess file below
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^car-for-sale/(.*)/(.*) car-details.php?id=$1&something=$2 [NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Wordfence WAF
<IfModule LiteSpeed>
php_value auto_prepend_file '/home/shipley/public_html/wordfence-waf.php'
</IfModule>
<Files ".user.ini">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Files>
You must use anchor in your patterns:
RewriteRule ^car-for-sale/([^/]+)/([^/]+)/?$ car-details.php?id=$1&something=$2 [NC,L,QSA]
RewriteRule ^car-for-sale/([^/]+)/?$ car-details.php?id=$1 [NC,L,QSA]
Related
I have a site I administer but I inherited the code from a previous developer. He wrote some rewrite rules, most of which seem to do the necessary job.
However my client has now purchased a subdomain eg: http://shop.thesite.com
However running this in the browser just returns http://thesite.com
I have tried commenting out some of the rules to try and get the shop subdomain to work, but I cannot seem to do it.
Here are the contents of the htaccess file:
DirectoryIndex index.php index2.php index.html index.htm
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine On
########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.xml|\.feed|\.ajax|\.img|\.xhtml|/[^.]*)$ [NC]
RewriteRule (.*) index.php [L]
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
<Files *.inc.php>
order allow,deny
deny from all
</Files>
<Files pagecounter.inc.php>
order allow,deny
allow from all
</Files>
<IfModule mod_php5.c>
php_value upload_max_filesize 50M
</IfModule>
<IfModule mod_php4.c>
php_value upload_max_filesize 50M
</IfModule>
I realise that is alot of code, and this is probably not the most enlightened question, but I would appreciate some help.
This was the line that I thought was rewriting the subdomain:
RewriteRule (.*) index.php [L]
I did comment that out but it made no difference, so now I am also wondering if I am having to deal with any caching issues.
So I have been looking all over for a while, and cannot seem to find a particular solution I am looking for. I have seen many articles showing how to fix problems with wordpress rewrite, but none fix my problem.
I currently have Wordpress Installed in my / Root directory. the .htaccess looks like this.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^manager - [L,NC] <-- I added this from other examples.
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
So from what I can tell this tells wordpress, hey you will handle all the urls, for everything. forever. Seriously. For ever and everywhere :P
So the problem comes when I have a sub directory site.com/manager
Here I would like to build a similar URL capturing method to manage what the user gets to see/access/etc. The line I added to the root .htaccess file (from what I have read) is suppose to tell wordpress, hey don't touch my damn /manager folder.
Wordpress being the sneaky greedy caregiver that it is fails to listen. ill go to test my site.com/manager/test (grabbing test and pulling info from sql with it) and wordpress takes over and throws me to the wordpress 404 page.
my .htaccess in /manager is as follows for refrence, I am thinking I will need to do some rewrite stuffs here too, but for now just trying to prevent wordpress from being over bearing :).
DirectoryIndex index.php
<FilesMatch "\.(php|inc)$">
Order allow,deny
deny from all
</FilesMatch>
<FilesMatch "(index.php|logout.php)$">
Order allow,deny
allow from all
</FilesMatch>
Any ideas, thoughts, comments, concerns would be much appreciated.
Thank you.
SO after digging deeper and looking into this further I found a fix. Not sure it is the BEST solution but its working.
Root (/) .htaccess
#Manager - A customer content manager
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/manager/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>
#end Manager
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
This appears to over ride wordpress like needed.
Manager (/manager) .htaccess
DirectoryIndex index.php
<FilesMatch "\.(php|inc)$">
Order allow,deny
deny from all
</FilesMatch>
<FilesMatch "(index.php|logout.php|install.php)$">
Order allow,deny
allow from all
</FilesMatch>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /manager/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
The top portion isn't required but I added this for file protection/security.
Summary:
I used the %{REQUEST_URI} to selectively remove a sub-folder, to apply this to more sub-folders I would add another
RewriteCond %{REQUEST_URI} ^/manager/(.*)$ [OR]
I then input the information in the sub-directory's .htaccess file for url rewriting. From here I can manipulate the URL converting it into a Array list for further sorting and database calling.
This is a rule in htaccess file :
RewriteRule ^Serie-examens-([0-9]+)-([0-9]+)-([a-zA-Z]+)$ examens-list.php?idChapitre=$1&idTitre=$2 [L]
In href i've put this url :
href="<?php echo 'Serie-examens-'.$idChapitre.'-'.$idTitres[0].'-debuter');?>"
i've this error when i click in the link :
Not Found
The requested URL /SerieJava/Serie-examens-1-1-debuter was not found on this server.
I'm using wamp, and i test rewriting url without variables , it works
where is the error in the rule ?
The Full .htaccess file :
SetEnv REGISTER_GLOBALS 0
<Files .htaccess>
order allow,deny
deny from all
</Files>
Options -Indexes
RewriteEngine On
RewriteBase /SerieJava/
RewriteRule ^Le-premier-chapitre chapitre1.php [L]
RewriteRule ^Serie-examens-([0-9]+)-([0-9]+)-([a-zA-Z]+)$ examenss-list.php?idChapitre=$1&idTitre=$2 [L]
thanks
You have a closing ) in the link php that should not be there:
href="<?php echo 'Serie-examens-'.$idChapitre.'-'.$idTitres[0].'-debuter');?>"
^ here
That probably leads to a php error that invalidates your link.
Edit: Also note that you are using this to rewrite:
RewriteRule ^Serie-examens-([0-9]+)-([0-9]+)-([a-zA-Z]+)$ examens-list.php?idChapitre=$1&idTitre=$2 [L]
The ^ denotes the start so if your path is /SerieJava/Serie-examen.... it will not be rewritten because it starts with /SerieJava/.
You should post the whole .htaccess file to see if that is the problem but it looks like it is.
This should be your /SerieJava/.htaccess:
SetEnv REGISTER_GLOBALS 0
<Files .htaccess>
order allow,deny
deny from all
</Files>
Options -Indexes
RewriteEngine On
RewriteBase /SerieJava/
RewriteRule ^Le-premier-chapitre chapitre1.php [L,NC]
RewriteRule ^Serie-examens-([0-9]+)-([0-9]+) examens-list.php?idChapitre=$1&idTitre=$2 [L,QSA,NC]
Try adding a / to your rewrite rule:
RewriteEngine On
RewriteBase /SerieJava
RewriteRule ^/Serie-examens-([0-9]+)-([0-9]+)-([a-zA-Z]+)$ examens-list.php?idChapitre=$1&idTitre=$2 [L]
Notice the / after the ^ and before Serie
You may also try removing the carot from the rule:
RewriteEngine On
RewriteBase /SerieJava/
RewriteRule Serie-examens-([0-9]+)-([0-9]+)-([a-zA-Z]+)$ examens-list.php?idChapitre=$1&idTitre=$2 [L]
I know this question is more appropriate for Server Fault but unfortunately I was banned for poor quality questions (I was down voted on 2-3 questions I asked.) So the next best place to ask these questions are here.
I have two problems related to CodeIgniter routing.
The first problem is that I can't seem to get rid of index.php in the url. I followed the instructions on how to remove it. I have the following mod rewrite code in my .htaccess file (see below) at the root of my WAMP server (CI is located at the root, not in its own folder). I have uncommented this line in httpd.conf file LoadModule rewrite_module modules/mod_rewrite.so. I deleted index.php from $config['index_page'] = "index.php";. And I restarted all WAMP services.
My second problem is that I have a controller called search and a method called index. I would like to change the resultant URL from http://localhost/index.php/search/index to http://localhost/search/whatever_im_searching_for. I tried the following custom route in my routes.php file but it did not work: $route['search/(.*)'] = "search/$1";
RewriteEngine On
# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/site_folder/, use /site_folder/
RewriteBase /
# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
I am struggling to understand the code in .htaccess and on how to use CI's custom routing. Any assistance will be greatly appreciated. Thank you in advance.
EDIT 1
Edit your htaccess like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^LoginTut.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond $1 !^(index\.php|images|table-images|js|robots\.txt|css|captcha)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
To have your searchterms in the url you can look at this:
https://stackoverflow.com/a/12070284/1379394
Second problem:
$route['search/(:any)'] = "search/index/$1";
Check Apache's default config file. On WAMP it's probably in
<WAMPSERVER_HOME>\bin\apache\Apache2.2.xx\conf
If it looks like this:
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
then change both:
AllowOverride None
to:
AllowOverride All
I had the same problem and I fixed only by write in my .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
and it's working perfectly.
I am trying to use fuelcms in my arch linux lamp server. But I cant make htaccess to work. My home folder is ytsejam/fuel_cms/..
This is my .htaccess file :
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
<Files .*>
Order deny, allow
Deny From All
</Files>
# Allow asset folders through
RewriteRule ^(fuel/modules/(.+)?/assets/(.+)) - [L]
# Protect application and system files from being viewed
RewriteRule ^(fuel/install/.+|fuel/crons/.+|fuel/data_backup/.+|fuel/codeigniter/.+|fuel/modules/.+|fuel/application/.+|\.git.+) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [L]
</IfModule>
Options -Indexes
/var/log/httpd/error_logs show that
/home/ytsejam/public_html/fuel_cms/.htaccess: order takes one argument, 'allow,deny', 'deny,allow', or 'mutual-failure'
can anyone help me ?
You have just inserted additional space after the comma
"deny, allow" must be "deny,allow"