mod-rewrite

Htaccess redirect all .html pages to php get variables

旧城冷巷雨未停 提交于 2019-12-24 09:15:07
问题 My urls are currently like: /events.html /contact.html What I want to do is, redirect them to a php get variable. E.g events.html = index.php?page=events Any ideas on how this could be accomplished? Thanks A lot. 回答1: You are looking for mod_rewrite here. With the rule something along the lines of (assuming mod_rewrite is installed and enabled and you're putting it in a .htaccess file) RewriteEngine on RewriteRule ^/(.*).html /index.php?page=$1 来源: https://stackoverflow.com/questions/11670997

My css imges js path is changed after using of mod_rewrite

混江龙づ霸主 提交于 2019-12-24 08:59:26
问题 I have changed my url from http://example.com/course.php?id=1001 To http://example.com/course/1001 but after changing the url of all the css js and images is not working I have use this code RewriteEngine On RewriteRule ^course/([A-Za-z0-9-]+)/?$ coursedetails.php?id=$1 [NC,L] 回答1: one solution is that use absolute path (ex /css, or /js rather than just css/, /js but this is not looks a reliable solution since we've to change it on all files, This is because your relative URIs have their base

Mod_rewrite: hide query string from users with sub domain

两盒软妹~` 提交于 2019-12-24 08:49:12
问题 I am trying to do something very simple yet still confusing. I have a link http://sub.example.com/folder/?qvar=value I want this to be accessible via: http://sub.example.com/folder/value Very simple yet I cannot figure this out. I have tried the following to no avail: #RewriteEngine On #RewriteRule ^(.*)$ ?qvar=$1 [L, QSA] #RewriteRule ^(.*)$ /folder/index.php?qvar=$1 [L,QSA] #RewriteRule ^(.*)$ index.php?qvar=$1 [L,QSA] #RewriteRule ^(.*)$ /folder/?qvar=$1 [L,QSA] #RewriteRule ([^/\.]+)/?$

mod-rewrite for URLs with extra characters after second slash

主宰稳场 提交于 2019-12-24 08:48:06
问题 How to return 404 error for all URL with extra characters after second / by htaccess. e.g1: http://www.example.com/blah-blah/ NOT Redirect (no extra characters after 2th / ) e.g2: http://www.example.com/blah-blah/blah-blah Redirect to 404 e.g3: http://www.example.com/blah-blah/blah-blah/ Redirect to 404 e.g4: http://www.example.com/blah-blah/blah-blah/blah-blah Redirect to 404 e.g5: http://www.example.com/blah-blah/blah-blah/blah-blah/ Redirect to 404 I tried this but not works with e.g3 & e

Redirect root to CodeIgniter app in subdir, avoiding infinite loop

こ雲淡風輕ζ 提交于 2019-12-24 08:38:10
问题 I currently have deployed the following .htaccess in the directory of my CodeIgniter app: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] and the following .htaccess in my htdocs root: RewriteEngine On # Map / to /foo. RewriteRule ^$ /foo/ [L] # Map /x to /foo/x unless there is a x in the web root. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/foo/ RewriteRule ^

Stop accessing my domain using htaccess

好久不见. 提交于 2019-12-24 08:38:05
问题 I've multiple domain hosting account and so I've hosted multiple domains on that. So I want to separate those with the main domain. Main hosting : https://example.com Other hosted website : https://mydomain1.com, https://mydomain2.com Other hosted websites are under path https://example.com/domains/mydomain1 https://example.com/domains/mydomain2 So anyone can access the other domain using the above mentioned paths(if he knows) So to separate all domains I want if anyone accessing the domains

Why is my LAST rule [L] not working in apache?

感情迁移 提交于 2019-12-24 08:28:30
问题 Background, I'm running a Zend Framework application. Trying to squeeze the most performance out of it as possible. So I'm trying to move the rules out of .htaccess exactly to the letter per this blog post by the author of a Zend Framework book: http://www.armando.ws/2009/03/how-to-run-zend-framework-with-no-htaccess-file/ So basically, in httpd.conf, I'm adding an include to conf/extra/httpd-zf.conf which contains the same thing that was in my .htaccess file and working perfectly. Here's the

Removing .php extensions from files in htdocs

心不动则不痛 提交于 2019-12-24 08:21:50
问题 I have my project in my htdocs folder where my main file is index.php . I have tried multiple time to remove the .php extension when the file is opened in the browser, using the .htaccess file with the following lines without luck: RewriteEngine On RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [L] The extension remains. Is it because the link in my browser is file:///C:/wamp64/bin/apache/apache2.4.23/htdocs/Cipcpr/index.php and not localhost/... 回答1: You

rewrite showing only text without pictures and external javascript

谁都会走 提交于 2019-12-24 07:46:49
问题 I have code below: RewriteEngine On RewriteBase / RewriteCond %{HTTP_USER_AGENT} (mozilla|navigator|chrome) [NC] RewriteRule ^newfolder/(.*)$ /index.html [L,NC] Problem is because it rewrite everything to index.html - it means that picture and external JavaScript won't be seen (loaded)... It only rewrite index.html (text) but other stuff from index not (picture, external JavaScript). With [L,NC,R] work but whith [L,NC] not and I don't want visitors to see that is other page. I want to show

make an url password protected from direct accessing htaccess

时光怂恿深爱的人放手 提交于 2019-12-24 07:46:08
问题 I am new to .htaccess . I have two files named page1.php and page2.php ,while page2.php is in another folder and page1.php has a link to it.I want to make page2.php password protected when someone wants to open page2.php directly hitting the URL. But it should be open when someone wants to go to that page from page1.php page. Can anyone help me out to get this done? Note:I have already added the following thing to my .htaccess . But here this page is password protected in both ways no matter