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]
Related
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]
I do not know why, but this simple Rule will not work.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^rubbellos\.png/$ rubbellos/rubbelbild_png.php [NC,L]
RewriteRule ^rubbellos\.css/$ rubbellos/rubbellos_css.php [NC,L]
</IfModule>
If I copy the xyz/rubbellos/rubbelbild_png.php to browser it is OK.
My approach is to bring the request of rubbellos.png to the .php-file. But I get a file not found.
Thx for any hint in advance.
You have 2 errors:
use a RewriteBase since you're talking about a subdirectory /xyz/ in your question.
disable MultiViews option to avoid unexpected behaviour with rubbellos (virtual file and existing directory).
You can replace your current code by this one in your htaccess (which has to be in /xyz/ folder)
Options -MultiViews
RewriteEngine On
RewriteBase /xyz/
RewriteRule ^rubbellos\.png$ rubbellos/rubbelbild_png.php [L]
RewriteRule ^rubbellos\.css$ rubbellos/rubbellos_css.php [L]
Note: don't forget to replace xyz by your real subdirectory's name
I now have:
Order deny,allow
Options +FollowSymlinks
RewriteEngine on
DirectoryIndex index.php
RewriteRule ^en/newsevents$ ?action=setLang&lang=eng&menuid=6 [L,QSA]
It loads my texts but thiks it must look in the /en folder.
This does work, but changes the url from localhost/en/newsevents to localhost/name/?action=setLang&lang=eng&menuid=6
I want that it still remains localhost/en/newsevents
RewriteRule ^en/newsevents$ `http://localhost/name/?action=setLang&lang=eng&menuid=6 [L,QSA]`
Just do this:
RewriteRule ^(en/newsevents)$ $1?action=setLang&lang=eng&menuid=6 [QSA,L]
You need to use passthrough
RewriteRule ^en/newsevents$ ?action=setLang&lang=eng&menuid=6 [PT,L,QSA]
here is my .htaccess code
Options all -Indexes
<Files .htaccess>
order allow,deny
deny from all
</Files>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^thumb/(.*)$ thumb.php?imagePath=$1 [B]
</IfModule>
If i enter url as http://mydomain.com/thumb/image1.jpg then its passed to thumb.php?imagePath=image.1, and its working fine.
suppose if i enter url as http://mydomain.com/thumb/http://otherwebsite.com/images/image1.jpg
then its showing 404 error. Please help me to sort out this issue
And i used encodedurl too like this http://mydomain.com/thumb/http%3A%2F%2Fotherwebsite.com%2Fimages%2Fimage1.jpg
Same i got 404 Error. Please help me to sort out this.
To use a parameter with http:// you need to use capture the URI using THE_REQUEST variable. THE_REQUEST variable that represents original request received by Apache from your browser
Try this rule:
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{THE_REQUEST} \s/+thumb/(\S+) [NC]
RewriteRule ^ thumb.php?imagePath=%1 [B,L,NE]
Why have you add a / at the end of your rule ?
Try this :
Options all -Indexes
<Files .htaccess>
order allow,deny
deny from all
</Files>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^thumb/(.*)$ thumb.php?imagePath=$1 [B]
</IfModule>
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.