dqwyghl0649 2016-01-06 05:38 采纳率: 0%
浏览 71
已采纳

codeigniter seo url with htaccess

I`m using Codeigniter 3.0.3

I need to use link like this

http://www.example.com/my-controller/my-function/my-value1/other-value2/other-value3/value4

I have this htaccess

# Disable file indexing
Options -Indexes
# Follow symbolic links.
Options +FollowSymLinks

php_value upload_max_filesize 16M
php_value post_max_size 16M
php_value max_input_vars 1000000

# Compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# adding type for .woff2:
AddType application/x-font-woff2 .woff2
# adding type for .woff:
AddType application/x-font-woff .woff
AddType application/vnd.ms-word.document.macroEnabled.12 .docm
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
AddType application/vnd.ms-powerpoint.template.macroEnabled.12 potm
AddType application/vnd.openxmlformats-officedocument.presentationml.template potx
AddType application/vnd.ms-powerpoint.addin.macroEnabled.12 ppam
AddType application/vnd.ms-powerpoint.slideshow.macroEnabled.12 ppsm
AddType application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
AddType application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm
AddType application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
AddType application/vnd.ms-excel.addin.macroEnabled.12 xlam
AddType application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb
AddType application/vnd.ms-excel.sheet.macroEnabled.12 xlsm
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
AddType application/vnd.ms-excel.template.macroEnabled.12 xltm

# Prevent viewing of htaccess file.
<Files .htaccess>
    order allow,deny
    deny from all
</Files>

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /

    # Set REQUEST_SCHEME (standard environment variable in Apache 2.4)
    RewriteCond %{HTTPS} off
    RewriteRule .* - [E=REQUEST_SCHEME:http]

    RewriteCond %{HTTPS} on
    RewriteRule .* - [E=REQUEST_SCHEME:https]

    # Check for POST Submission
    RewriteCond %{REQUEST_METHOD} !^POST$

    # Redirect to domain with www.
    RewriteCond %{HTTPS} off
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{SERVER_NAME} !^www\. [NC]
    RewriteRule .* http://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

    # Redirect to domain with www.
    RewriteCond %{HTTPS} on
    RewriteCond %{SERVER_PORT} 443
    RewriteCond %{SERVER_NAME} !^www\. [NC]
    RewriteRule .* https://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

    ### Canonicalize codeigniter URLs

    # If your default controller is something other than
    # "welcome" you should probably change this
    RewriteRule ^(index(/index)?|index(\.php)?)/?$ / [L,R=301]
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]

    # Removes trailing slashes (prevents SEO duplicate content issues)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ $1 [L,R=301]

    ###
    # Removes access to the system folder by users.
    # Additionally this will allow you to create a System.php controller,
    # previously this would not have been possible.
    # 'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

    # Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # Without mod_rewrite, route 404's to the front controller
    ErrorDocument 404 /index.php
</IfModule>

now I need to owerwrite - to _ so the real url will be like this

/my_controller/my_function/my_value1/other_value2/other_value3/value4

how can I do this?

  • 写回答

1条回答 默认 最新

  • dragon7088 2016-01-06 06:41
    关注

    In your config/routes.php file:

    You can define this URL:

    /my-controller/my-function/(:any)/other_value2/other_value3/value4
    

    As:

    $route['my-controller/my-function/(:any)/(:any)/(:any)'] = "my_controller/my_function/$1/$2/$3";
    

    Here, these 3 (:any) means your three params rest url you can use any thing do you.

    One more example with simple route:

    $route['about-us'] = "aboutus";
    

    Here aboutus is my controller name, and i want to access it as

    http://localhost/project/about-us
    

    Than i can use like that.

    Side Note: You can get URL values by using uri->segment().

    User Guide

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作